package com.kkb.shopcenter.filter;

import com.kkb.shopcenter.api.UserInfoService;
import com.kkb.shopcenter.common.pojo.UserDetailsImp;
import com.kkb.shopcenter.common.pojo.UserInfo;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;


@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Reference
    private UserInfoService userInfoService;


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        UserDetailsImp userDetailsImp = new UserDetailsImp();

        UserInfo userInfo = userInfoService.findByUsername(username);

        if(userInfo==null){
            throw  new UsernameNotFoundException(username+"用户不存在");
        }

        userDetailsImp.setUserName(username);

        userDetailsImp.setUserPassword(userInfo.getUserPassword());

        return  userDetailsImp;

    }
}
